Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (19)

Q1 Program to find string is palindrome or not.


string=input("enter string1") l=len(string) rev=-1 for i in range(len(string)): if string[i]==string[rev]: i+=1 rev-=1 else: print(string ,"is not palindrome") break else: print(string,"is a palindrome") Output >>> ==================== RESTART: C:/Users/Dell/Desktop/dd.py ==================== enter string1mam mam is a palindrome >>> ==================== RESTART: C:/Users/Dell/Desktop/dd.py ==================== enter string1ram ram is not palindrome



Q2.Program of calculator using else if.


a=int(input("enter number1")) b=int(input("enter number2")) ch=input("enter choce") if(ch=='+'): c=a+b print(c) elif(ch=='-'): c=a-b print(c) elif(ch=='*'): c=a*b print(c) else: c=a/b print(c) >>> ==================== RESTART: C:/Users/Dell/Desktop/dd.py ==================== enter number12 enter number23 enter choce+ 5 >>> ==================== RESTART: C:/Users/Dell/Desktop/dd.py ==================== enter number12 enter number23 enter choce/ 0.6666666666666666



Q3.Program to convert decimal to binary.


n=int(input("enter a number")) bn="" re="" de=-1 while(n>=1): r=str(int(n%2)) n=n/2 bn=bn+r for i in range(len(bn)): re=re+bn[de] de=de-1 print(re) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/dd.py ==================== enter a number15 1111 >>> ==================== RESTART: C:/Users/Dell/Desktop/dd.py ==================== enter a number100 1100100


Q4.Program to convert decimal to octal.


n=int(input("enter a number")) bn="" re="" de=-1 while(n>=1): r=str(int(n%8)) n=n/8 bn=bn+r for i in range(len(bn)): re=re+bn[de] de=de-1 print(re) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/dd.py ==================== enter a number12 14


Q5.Program to convert string in uppercase.


s1=input("enter string") s2=s1.upper() print(s2) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/dd.py ==================== enter stringram RAM



Post a Comment

0 Comments